#include <iostream>
#include <unistd.h>
#include <signal.h>

// volatile关键字的应用

volatile int flag = 0;

void handler(int sig)
{
    std::cout << "更改全局变量," << flag << "->1" << std::endl;
    flag = 1;
}

int main()
{
    struct sigaction act, oact;
    act.sa_handler = handler;
    sigemptyset(&act.sa_mask);
    act.sa_flags = 0;
    sigaction(SIGINT, &act, &oact);

    while (!flag)
        ;
    std::cout << "process normally quit!" << std::endl;

    return 0;
}
